package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.RechargeDataBean;
import com.zzsy.carosshopprojects.util.ConverterHelper;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

public class RechargeAdapter extends ViewHolderRecyclerAdapter<RechargeDataBean> {
    private int pos = -1;

    public RechargeAdapter(Context context, List<RechargeDataBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_reghter, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, RechargeDataBean rechargeDataBean, int positions) {
        helper.setText(R.id.tv_coupon_name, rechargeDataBean.getCouponName());
        String preAmount = rechargeDataBean.getPreAmount();
        String preKind = rechargeDataBean.getPreKind();
        String rebate = rechargeDataBean.getRebate();
        TextView tvTime = helper.getView(R.id.tv_time);
        if (!StringUtils.isEmpty(preKind)) {
            if ("1".equals(preKind)) {
                if (!StringUtils.isEmpty(preAmount)) {
                    String preAmountDou = ConverterHelper.toBigDecimal(preAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                    tvTime.setText("赠" + preAmountDou + "元");
                } else {
                    tvTime.setText("增值服务产品");
                }
            } else if ("2".equals(preKind)) {
                if (!StringUtils.isEmpty(preAmount)) {
                    String rebateDou = ConverterHelper.toBigDecimal(rebate).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
                    tvTime.setText(rebateDou + "折");
                } else {
                    tvTime.setText("增值服务产品");
                }
            }
        }

    }

}
